import React, { Component } from 'react';

class App extends Component {
  state = {
    file:''
  }

  /* 涉及到dom操作  不合适 */
  // componentDidMount () {
  //   document.getElementById('file').addEventListener('change',(e) => {
  //     console.log(e.target.files);
  //   })
  // }


  constructor(props){
    super(props);
    this.fileRef = React.createRef();
  }
  handleGetNode =  ()=>{
    console.log(this.fileRef);
    console.log(this.fileRef.current);
  }
  render() {
    return (
      <div>
        <input type="file" id='file' ref={this.fileRef} />
        <button onClick={this.handleGetNode}>获取file的元素节点</button>
      </div>
    );
  }
}

export default App;
